﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using NewDDSys.DATAOUT;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_RBDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ExcelEdit report = new ExcelEdit();
        report.CreateExcel();
        report.CreateWorkSheet("生产日报表");
        report.CellsUnite(1, 1, 1, 16);
        report.WriteData("作业情况", 1, 1);
        report.CellsAlignment(1, 1, 1, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("库区", 2, 1);
        report.WriteData("品种", 2, 2);
        report.WriteData("作业内容", 2, 3);
        report.WriteData("待装卸车数", 2, 4);
        report.WriteData("好车数", 2, 5);
        report.WriteData("坏车数", 2, 6);
        report.WriteData("货位", 2, 7);
        report.WriteData("配到时间", 2, 8);
        report.WriteData("空线时间", 2, 9);
        report.WriteData("装卸完时间", 2, 10);
        report.WriteData("完成车数", 2, 11);
        report.WriteData("装车用时", 2, 12);
        report.WriteData("封完时间", 2, 13);
        report.WriteData("延时", 2, 14);
        report.WriteData("挂出时间", 2, 15);
        report.WriteData("原因", 2, 16);
        System.Data.DataTable dtResult1 = MakeNamesTable5();
        DataSet ds1 = BLLFactory.CreateWorkBLL().SelectZYQK();
        if (ds1.Tables[0].Rows.Count != 0)
        {
            for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
            {
                
                System.Data.DataRow dtRow1 = dtResult1.NewRow();
                int j = 0;
                dtRow1[j++] = ds1.Tables[0].Rows[i]["ku"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["pinzhong"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["neirong"].ToString();
                string num = ds1.Tables[0].Rows[i]["num"].ToString();
                DataSet ds2 = BLLFactory.CreateDxcBLL().SelectNum(num);
                if (ds2 != null)
                    dtRow1[j++] = ds2.Tables[0].Rows[0]["cs"].ToString();
                else
                    dtRow1[j++] = "";
                dtRow1[j++] = ds1.Tables[0].Rows[i]["good"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["bad"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["pos"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["pdtime"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["kx"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["zwtime"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["wcs"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["zcys"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["fwtime"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["ys"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["gctime"].ToString();
                dtRow1[j] = ds1.Tables[0].Rows[i]["yuanyin"].ToString();
                dtResult1.Rows.Add(dtRow1);
            }
        }
        report.WriteData(dtResult1, 3, 1);
        int m = dtResult1.Rows.Count;
        int n = 3 + m;
        report.CellsUnite(n, 1, n, 13);
        report.WriteData("当班情况统计", n, 1);
        report.CellsAlignment(n, 1, n, 13, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("外发", n+2, 1);
        report.WriteData("倒库", n+3, 1);
        report.WriteData("返厂", n+4, 1);
        report.WriteData("倒装", n+5, 1);
        report.WriteData("零提", n+6, 1);
        report.WriteData("库区", n+1, 1);
        report.WriteData("嘉东库", n+1, 2);
        report.WriteData("板材库", n+1, 3);
        report.WriteData("不锈钢热轧库", n+1, 4);
        report.WriteData("不锈钢冷轧库", n+1, 5);
        report.WriteData("碳钢热轧库", n+1, 6);
        report.WriteData("碳钢冷轧库", n+1, 7);
        report.WriteData("一高线", n+1, 8);
        report.WriteData("二高线", n+1, 9);
        report.WriteData("大棒线", n+1, 10);
        report.WriteData("四轧库", n+1, 11);
        report.WriteData("酸洗库", n+1, 12);
        report.WriteData("化产库", n+1, 13);
        string[] s1 = { "外发", "倒库", "返厂", "倒装", "零提" };
        string[] s2 = { "嘉东库", "板材库", "不锈钢热轧库", "不锈钢冷轧库", "碳钢热轧库", "碳钢冷轧库", "一高线", "二高线", "大棒线", "四轧库", "酸洗库", "化产库" };
        DateTime bb = Convert.ToDateTime("08:00:00");
        DateTime yb = Convert.ToDateTime("20:00:00");
        DateTime tN = DateTime.Now;
        string Nt = tN.ToString();
        string t1 = "";
        string t2 = "";
        if (DateTime.Compare(tN, bb) <= 0)
            t1 = yb.AddDays(-1).ToString();
        else if (DateTime.Compare(tN, yb) >= 0)
            t1 = yb.ToString();
        else
            t1 = bb.ToString();
        t2 = Convert.ToDateTime(t1).AddHours(12).ToString();
        int cs = 0;
        int ycs = 0;
        System.Data.DataTable dtResult2 = MakeNamesTable1();
        foreach (string neirong in s1)
        {

            System.Data.DataRow dtRow2 = dtResult2.NewRow();
            int j = 0;
            foreach (string ku in s2)
            {
                string kucs = "";
                string cl = "";
                if (ku == "嘉东库")
                {
                    kucs = BLLFactory.CreateWorkBLL().JDCS(t1, Nt, neirong);
                    if (kucs != "")
                        cs = Convert.ToInt32(kucs);
                    cl = BLLFactory.CreateDxcBLL().JDY(t1, Nt, neirong);
                    if (cl != "")
                        ycs = Convert.ToInt32(cl);
                    cs = cs + ycs;
                }
                else
                {
                    kucs = BLLFactory.CreateWorkBLL().csbyzk(neirong, ku);
                    if (kucs != "")
                        cs = Convert.ToInt32(kucs);
                    DataSet ds = BLLFactory.CreateDxcBLL().NRYCL(t2, ku, neirong);
                    string csy = ds.Tables[0].Rows[0]["csy"].ToString();
                    if (csy != "")
                        ycs = Convert.ToInt32(csy);
                    cs = cs + ycs;
                }
                

                dtRow2[j++] = cs.ToString();
                cs = 0;
                ycs = 0;

            }
            dtResult2.Rows.Add(dtRow2);

        }
        report.WriteData(dtResult2, n+2, 2);
        report.CellsUnite(n, 14, n, 16);
        report.WriteData("嘉东待卸车", n, 14);
        report.CellsAlignment(n, 14, n, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("库内", n+1, 14);
        report.WriteData("库外", n+1, 15);
        report.WriteData("站内", n+1, 16);
        DataSet ds3 = BLLFactory.CreateJddxBLL().dxqk();
        string kn = ds3.Tables[0].Rows[0]["kn"].ToString();
        report.WriteData(kn, n + 2, 14);
        string kw = ds3.Tables[0].Rows[0]["kw"].ToString();
        report.WriteData(kw, n + 2, 15);
        string zn = ds3.Tables[0].Rows[0]["zn"].ToString();
        report.WriteData(zn, n + 2, 16);
        
        n = n + 7;
        report.CellsUnite(n, 1, n, 11);
        report.WriteData("交班库存情况", n, 1);
        report.CellsAlignment(n, 1, n, 11, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("嘉东库", n+2, 1);
        report.WriteData("线材", n + 1, 2);
        string jdxc = BLLFactory.CreateJbBLL().JDXC();
        report.WriteData(jdxc, n + 2, 2);
        report.WriteData("螺纹", n + 1, 3);
        string jdbc = BLLFactory.CreateJbBLL().JDBC();
        report.WriteData(jdbc, n + 2, 3);
        report.WriteData("板材", n + 1, 4);
        string jdzb = BLLFactory.CreateJbBLL().JDZB();
        report.WriteData(jdzb, n + 2, 4);
        report.WriteData("CSP库存", n + 1, 5);
        string tgr = BLLFactory.CreateJbBLL().JDTGR();
        string tgl = BLLFactory.CreateJbBLL().JDTGL();
        decimal tgrkc = 0;
        if (tgr != "")
            tgrkc = Convert.ToDecimal(tgr);
        decimal tglkc = 0;
        if (tgl != "")
            tglkc = Convert.ToDecimal(tgl);
        decimal csp = tgrkc + tglkc;
        report.WriteData(csp.ToString("f2"), n + 2, 5);
        report.WriteData("CSP合格", n + 1, 6);
        string tgrh = BLLFactory.CreateJbBLL().JDTGRH();
        string tglh = BLLFactory.CreateJbBLL().JDTGLH();
        decimal tgrhg = 0;
        if (tgrh != "")
            tgrhg = Convert.ToDecimal(tgrh);
        decimal tglhg = 0;
        if (tglh != "")
            tglhg = Convert.ToDecimal(tglh);
        decimal csph = tgrhg + tglhg;
        report.WriteData(csph.ToString("f2"), n + 2, 6);
        report.WriteData("CSP可利用", n + 1, 7);
        string tgk = BLLFactory.CreateJbBLL().JDTGRK();
        report.WriteData(tgk, n + 2, 7);
        report.WriteData("CSP未缴库", n + 1, 8);
        string tgrw = BLLFactory.CreateJbBLL().JDTGRW();
        string tglw = BLLFactory.CreateJbBLL().JDTGLW();
        decimal tgrwj = 0;
        if (tgrw != "")
            tgrwj = Convert.ToDecimal(tgrw);
        decimal tglwj = 0;
        if (tglw != "")
            tglwj = Convert.ToDecimal(tglw);
        decimal cspw = tgrwj + tglwj;
        report.WriteData(cspw.ToString("f2"), n + 2, 8);
        report.WriteData("不锈钢库存", n + 1, 9);
        string bxr = BLLFactory.CreateJbBLL().JDBXR();
        string bxl = BLLFactory.CreateJbBLL().JDBXL();
        decimal bxrk = 0;
        if (bxr != "")
            bxrk = Convert.ToDecimal(bxr);
        decimal bxlk = 0;
        if (bxl != "")
            bxlk = Convert.ToDecimal(bxl);
        decimal bxk = bxrk + bxlk;
        report.WriteData(bxk.ToString("f2"), n + 2, 9);
        report.WriteData("不锈钢合格", n + 1, 10);
        string bxrh = BLLFactory.CreateJbBLL().JDBXRH();
        string bxlh = BLLFactory.CreateJbBLL().JDBXLH();
        decimal bxrhg = 0;
        if (bxrh != "")
            bxrhg = Convert.ToDecimal(bxrh);
        decimal bxlhg = 0;
        if (bxlh != "")
            bxlhg = Convert.ToDecimal(bxlh);
        decimal bxh = bxrhg + bxlhg;
        report.WriteData(bxh.ToString("f2"), n + 2, 10);
        report.WriteData("不锈钢可利用", n + 1, 11);
        string bxkc = BLLFactory.CreateJbBLL().JDBXRK();
        report.WriteData(bxkc, n + 2, 11);
        report.WriteData("板材库", n+2, 12);
        report.WriteData("库存", n + 1, 13);
        report.WriteData("合格", n + 1, 14);
        report.WriteData("未缴库", n + 1, 15);
        DataSet ds11 = BLLFactory.CreateJbBLL().ZBKC();
        string zbkc = ds11.Tables[0].Rows[0]["zbkc"].ToString();
        report.WriteData(zbkc, n + 2, 13);
        string zbhg = ds11.Tables[0].Rows[0]["zbhg"].ToString();
        report.WriteData(zbhg, n + 2, 14);
        string zbwj = ds11.Tables[0].Rows[0]["zbwj"].ToString();
        report.WriteData(zbwj, n + 2, 15);
        report.WriteData("其它库库存", n+4, 1);
        report.WriteData("一高线", n + 3, 2);
        string xc1g = BLLFactory.CreateJbBLL().XCKC("一高线");
        string bc1g = BLLFactory.CreateJbBLL().BCKC("一高线");
        decimal xc1gkc = 0;
        if (xc1g != "")
            xc1gkc = Convert.ToDecimal(xc1g);
        decimal bc1gkc = 0;
        if (bc1g != "")
            bc1gkc = Convert.ToDecimal(bc1g);
        decimal kc1g = xc1gkc + bc1gkc;
        report.WriteData(kc1g.ToString("f2"), n + 4, 2);
        report.WriteData("二高线", n + 3, 3);
        string xc2g = BLLFactory.CreateJbBLL().XCKC("二高线");
        decimal xc2gkc = 0;
        if (xc2g != "")
            xc2gkc = Convert.ToDecimal(xc2g);
        report.WriteData(xc2gkc.ToString("f2"), n + 4, 3);
        report.WriteData("大棒线", n + 3, 4);
        string bcbg = BLLFactory.CreateJbBLL().BCKC("大棒线");
        
        decimal bcbgkc = 0;
        if (bcbg != "")
            bcbgkc = Convert.ToDecimal(bcbg);
        report.WriteData(bcbgkc.ToString("f2"), n + 4, 4);
        report.WriteData("四轧库", n + 3, 5);
        string bc4g = BLLFactory.CreateJbBLL().BCKC("四轧库");
        
        decimal bc4gkc = 0;
        if (bc4g != "")
            bc4gkc = Convert.ToDecimal(bc4g);
        report.WriteData(bc4gkc.ToString("f2"), n + 4, 5);
        report.WriteData("酸洗库", n + 3, 6);
        string sxkc = BLLFactory.CreateJbBLL().SXKC();
        report.WriteData(sxkc, n + 4, 6);
        n = n + 5;
        report.CellsUnite(n, 1, n, 8);
        report.WriteData("交班设备情况", n, 1);
        report.CellsAlignment(n, 1, n, 8, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        DataSet ds12 = BLLFactory.CreateJbBLL().JBSB();
        report.WriteData("库区", n+1, 1);
        report.WriteData("班别", n + 1, 2);
        report.CellsUnite(n, 3, n, 8);
        report.WriteData("设备情况", n, 3);
        report.CellsAlignment(n, 3, n, 8, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        int c = ds12.Tables[0].Rows.Count;
        if (c != 0)
        {
            for (int p = 0; p < c; p++)
            {
                int q = n + p + 2;
                report.CellsUnite(q, 3, q, 8);
                report.WriteData(ds12.Tables[0].Rows[p]["shebei"].ToString(), q, 3);
                report.CellsAlignment(q, 3, q, 8, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
            }
        }
        report.CellsUnite(n, 9, n, 16);
        report.WriteData("交班延续业务", n, 9);
        report.CellsAlignment(n, 9, n, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("库区", n + 1, 9);
        report.WriteData("班别", n + 1, 10);
        report.CellsUnite(n+1, 11, n+1, 16);
        report.WriteData("延续业务", n+1, 11);
        report.CellsAlignment(n+1, 11, n+1, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        DataSet ds13 = BLLFactory.CreateJbBLL().JBYX();
        int g = ds13.Tables[0].Rows.Count;
        if (g != 0)
        {
            for (int h = 0; h < g; h++)
            {
                int a = n + h + 2;
                report.CellsUnite(a, 11, a, 16);
                report.WriteData(ds13.Tables[0].Rows[h]["yanxu"].ToString(), a, 11);
                report.CellsAlignment(a, 11, a, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
            }
        }
        
        string title = Session["用户信息.单位"].ToString() + Session["用户信息.姓名"].ToString() + DateTime.Now.ToString("yyyyMMdd").Trim() + "生产日报表";
        string savepath = "zyqk\\" + title + ".xls";
        string RepPath = Server.MapPath(savepath);

        report.SaveAs(RepPath); //文档路径
        report.Close();
        string filename = title + ".xls";

        string spath = "zyqk\\" + filename;
        string RPath = Server.MapPath(spath);
        FileInfo f = new FileInfo(RPath);
        if (f.Exists)
        {

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
            Response.ContentType = "application/msexcel";
            Response.WriteFile(RPath);
            Response.Flush();
            Response.Close();
            f.Delete();
        }
    }
    
    private System.Data.DataTable MakeNamesTable1()
    {
        // Create a new DataTable titled 'Names.'
        System.Data.DataTable namesTable = new System.Data.DataTable("tb");

        // Add three column objects to the table.
        DataColumn jdColumn = new DataColumn();
        jdColumn.DataType = System.Type.GetType("System.String");
        
        
        namesTable.Columns.Add(jdColumn);

        DataColumn bcColumn = new DataColumn();
        bcColumn.DataType = System.Type.GetType("System.String");
        

        namesTable.Columns.Add(bcColumn);

        DataColumn bxrzColumn = new DataColumn();
        bxrzColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(bxrzColumn);

        DataColumn bxlzColumn = new DataColumn();
        bxlzColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(bxlzColumn);

        DataColumn tgrzColumn = new DataColumn();
        tgrzColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(tgrzColumn);

        DataColumn tglzColumn = new DataColumn();
        tglzColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(tglzColumn);

        DataColumn ygColumn = new DataColumn();
        ygColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(ygColumn);

        DataColumn egColumn = new DataColumn();
        egColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(egColumn);

        DataColumn dbColumn = new DataColumn();
        dbColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(dbColumn);

        DataColumn szColumn = new DataColumn();
        szColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(szColumn);

        DataColumn sxColumn = new DataColumn();
        sxColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(sxColumn);

        DataColumn hcColumn = new DataColumn();
        hcColumn.DataType = System.Type.GetType("System.String");
        
        namesTable.Columns.Add(hcColumn);
        // Return the new DataTable.
        return namesTable;
    }
    
    private System.Data.DataTable MakeNamesTable2()
    {
        // Create a new DataTable titled 'Names.'
        System.Data.DataTable namesTable = new System.Data.DataTable("tb");

        // Add three column objects to the table.
        DataColumn knColumn = new DataColumn();
        knColumn.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(knColumn);

        DataColumn wjColumn = new DataColumn();
        wjColumn.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(wjColumn);

        DataColumn klColumn = new DataColumn();
        klColumn.DataType = System.Type.GetType("System.String");

        namesTable.Columns.Add(klColumn);

        DataColumn dcColumn = new DataColumn();
        dcColumn.DataType = System.Type.GetType("System.String");

        namesTable.Columns.Add(dcColumn);

        
        // Return the new DataTable.
        return namesTable;
    }
    
    private System.Data.DataTable MakeNamesTable3()
    {
        // Create a new DataTable titled 'Names.'
        System.Data.DataTable namesTable = new System.Data.DataTable("tb");

        // Add three column objects to the table.
        DataColumn knColumn = new DataColumn();
        knColumn.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(knColumn);

        DataColumn kwColumn = new DataColumn();
        kwColumn.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(kwColumn);

        DataColumn znColumn = new DataColumn();
        znColumn.DataType = System.Type.GetType("System.String");

        namesTable.Columns.Add(znColumn);

        
        // Return the new DataTable.
        return namesTable;
    }
    
    private System.Data.DataTable MakeNamesTable4()
    {
        // Create a new DataTable titled 'Names.'
        System.Data.DataTable namesTable = new System.Data.DataTable("tb");

        // Add three column objects to the table.
        DataColumn sbColumn = new DataColumn();
        sbColumn.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(sbColumn);

        DataColumn yxColumn = new DataColumn();
        yxColumn.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(yxColumn);

        


        // Return the new DataTable.
        return namesTable;
    }

    private System.Data.DataTable MakeNamesTable5()
    {
        // Create a new DataTable titled 'Names.'
        System.Data.DataTable namesTable = new System.Data.DataTable("tb");

        // Add three column objects to the table.
        DataColumn ColumnKu = new DataColumn();
        ColumnKu.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnKu);

        DataColumn ColumnPz = new DataColumn();
        ColumnPz.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnPz);

        DataColumn ColumnNr = new DataColumn();
        ColumnNr.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnNr);

        DataColumn ColumnDx = new DataColumn();
        ColumnDx.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnDx);

        DataColumn ColumnGood = new DataColumn();
        ColumnGood.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnGood);

        DataColumn ColumnBad = new DataColumn();
        ColumnBad.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnBad);

        DataColumn ColumnPos = new DataColumn();
        ColumnPos.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnPos);

        DataColumn ColumnPd = new DataColumn();
        ColumnPd.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnPd);


        DataColumn ColumnKx = new DataColumn();
        ColumnKx.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnKx);

        DataColumn ColumnZw = new DataColumn();
        ColumnZw.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnZw);

        DataColumn ColumnWc = new DataColumn();
        ColumnWc.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnWc);

        DataColumn ColumnZcys = new DataColumn();
        ColumnZcys.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnZcys);

        DataColumn ColumnFw = new DataColumn();
        ColumnFw.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnFw);

        DataColumn ColumnYs = new DataColumn();
        ColumnYs.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnYs);

        DataColumn ColumnGc = new DataColumn();
        ColumnGc.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnGc);

        DataColumn ColumnYy = new DataColumn();
        ColumnYy.DataType = System.Type.GetType("System.String");


        namesTable.Columns.Add(ColumnYy);
        // Return the new DataTable.
        return namesTable;
    }
    protected void BindData()
    {
        string hday = HttpUtility.UrlDecode(Request["time"]??string.Empty);
        string banbie = HttpUtility.UrlDecode(Request["banbie"] ?? string.Empty);
        string bt = "";
        string et = "";
        if (banbie == "白")
        {
            bt = hday + "08:00:00";
            et = hday + "20:00:00";
        }
        else
        {
            bt = Convert.ToDateTime(hday).AddHours(20).ToString();
            et = hday + "08:00:00";
        }
        ExcelEdit report = new ExcelEdit();
        report.CreateExcel();
        report.CreateWorkSheet("生产日报表");
        report.CellsUnite(1, 1, 1, 16);
        report.WriteData("作业情况", 1, 1);
        report.CellsAlignment(1, 1, 1, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("库区", 2, 1);
        report.WriteData("品种", 2, 2);
        report.WriteData("作业内容", 2, 3);
        report.WriteData("待装卸车数", 2, 4);
        report.WriteData("好车数", 2, 5);
        report.WriteData("坏车数", 2, 6);
        report.WriteData("货位", 2, 7);
        report.WriteData("配到时间", 2, 8);
        report.WriteData("空线时间", 2, 9);
        report.WriteData("装卸完时间", 2, 10);
        report.WriteData("完成车数", 2, 11);
        report.WriteData("装车用时", 2, 12);
        report.WriteData("封完时间", 2, 13);
        report.WriteData("延时", 2, 14);
        report.WriteData("挂出时间", 2, 15);
        report.WriteData("原因", 2, 16);
        System.Data.DataTable dtResult1 = MakeNamesTable5();
        DataSet ds1 = BLLFactory.CreateWorkBLL().SelectZYQKH(bt, et);
        if (ds1.Tables[0].Rows.Count != 0)
        {
            for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
            {

                System.Data.DataRow dtRow1 = dtResult1.NewRow();
                int j = 0;
                dtRow1[j++] = ds1.Tables[0].Rows[i]["ku"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["pinzhong"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["neirong"].ToString();
                string num = ds1.Tables[0].Rows[i]["num"].ToString();
                DataSet ds2 = BLLFactory.CreateDxcBLL().SelectNum(num);
                if (ds2 != null)
                    dtRow1[j++] = ds2.Tables[0].Rows[0]["cs"].ToString();
                else
                    dtRow1[j++] = "";
                dtRow1[j++] = ds1.Tables[0].Rows[i]["good"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["bad"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["pos"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["pdtime"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["kx"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["zwtime"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["wcs"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["zcys"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["fwtime"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["ys"].ToString();
                dtRow1[j++] = ds1.Tables[0].Rows[i]["gctime"].ToString();
                dtRow1[j] = ds1.Tables[0].Rows[i]["yuanyin"].ToString();
                dtResult1.Rows.Add(dtRow1);
            }
        }
        report.WriteData(dtResult1, 3, 1);

        int m = dtResult1.Rows.Count;
        int n = 3 + m;
        report.CellsUnite(n, 1, n, 13);
        report.WriteData("当班情况统计", n, 1);
        report.CellsAlignment(n, 1, n, 13, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("外发", n + 2, 1);
        report.WriteData("倒库", n + 3, 1);
        report.WriteData("返厂", n + 4, 1);
        report.WriteData("倒装", n + 5, 1);
        report.WriteData("零提", n + 6, 1);
        report.WriteData("库区", n + 1, 1);
        report.WriteData("嘉东库", n + 1, 2);
        report.WriteData("板材库", n + 1, 3);
        report.WriteData("不锈钢热轧库", n + 1, 4);
        report.WriteData("不锈钢冷轧库", n + 1, 5);
        report.WriteData("碳钢热轧库", n + 1, 6);
        report.WriteData("碳钢冷轧库", n + 1, 7);
        report.WriteData("一高线", n + 1, 8);
        report.WriteData("二高线", n + 1, 9);
        report.WriteData("大棒线", n + 1, 10);
        report.WriteData("四轧库", n + 1, 11);
        report.WriteData("酸洗库", n + 1, 12);
        report.WriteData("化产库", n + 1, 13);
        string[] s1 = { "外发", "倒库", "返厂", "倒装", "零提" };
        string[] s2 = { "嘉东库", "板材库", "不锈钢热轧库", "不锈钢冷轧库", "碳钢热轧库", "碳钢冷轧库", "一高线", "二高线", "大棒线", "四轧库", "酸洗库", "化产库" };
        
        
        System.Data.DataTable dtResult2 = MakeNamesTable1();
        foreach (string neirong in s1)
        {

            System.Data.DataRow dtRow2 = dtResult2.NewRow();
            int j = 0;
            foreach (string ku in s2)
            {
                int cs = 0;
                int ycs = 0;
                int wcs = 0;
                string kucs = "";
                string cl = "";
                string w = "";
                if (ku == "嘉东库")
                {
                    kucs = BLLFactory.CreateWorkBLL().JDCS(bt, et, neirong);
                    if (kucs != "")
                        cs = Convert.ToInt32(kucs);
                    cl = BLLFactory.CreateDxcBLL().JDY(bt, et, neirong);
                    if (cl != "")
                        ycs = Convert.ToInt32(cl);
                    cs = cs + ycs;
                    w = BLLFactory.CreateDxcBLL().JDW(bt, et, neirong);
                    if (w != "")
                        wcs = Convert.ToInt32(w);
                    cs = cs - wcs;
                }
                else
                {
                    kucs = BLLFactory.CreateWorkBLL().csbyzkH(bt, et, neirong, ku);
                    if (kucs != "")
                        cs = Convert.ToInt32(kucs);
                    DataSet ds = BLLFactory.CreateDxcBLL().NRYCL(et, ku, neirong);
                    string csy = ds.Tables[0].Rows[0]["csy"].ToString();
                    if (csy != "")
                        ycs = Convert.ToInt32(csy);
                    cs = cs + ycs;
                    DataSet ds2 = BLLFactory.CreateDxcBLL().NRWCL(et, ku, neirong);
                    string csw = ds2.Tables[0].Rows[0]["csw"].ToString();
                    if (csw != "")
                        wcs = Convert.ToInt32(csw);
                    cs = cs - wcs;
                }


                dtRow2[j++] = cs.ToString();
                

            }
            dtResult2.Rows.Add(dtRow2);

        }
        report.WriteData(dtResult2, n + 2, 2);

        report.CellsUnite(n, 14, n, 16);
        report.WriteData("嘉东待卸车", n, 14);
        report.CellsAlignment(n, 14, n, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("库内", n + 1, 14);
        report.WriteData("库外", n + 1, 15);
        report.WriteData("站内", n + 1, 16);
        DataSet ds3 = BLLFactory.CreateJddxBLL().dxqkH(bt, et);
        string kn = ds3.Tables[0].Rows[0]["kn"].ToString();
        report.WriteData(kn, n + 2, 14);
        string kw = ds3.Tables[0].Rows[0]["kw"].ToString();
        report.WriteData(kw, n + 2, 15);
        string zn = ds3.Tables[0].Rows[0]["zn"].ToString();
        report.WriteData(zn, n + 2, 16);

        n = n + 7;
        report.CellsUnite(n, 1, n, 11);
        report.WriteData("交班库存情况", n, 1);
        report.CellsAlignment(n, 1, n, 11, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("嘉东库", n + 2, 1);
        report.WriteData("线材", n + 1, 2);
        string jdxc = BLLFactory.CreateJbBLL().JDXCL(bt, et);
        report.WriteData(jdxc, n + 2, 2);
        report.WriteData("螺纹", n + 1, 3);
        string jdbc = BLLFactory.CreateJbBLL().JDBCL(bt, et);
        report.WriteData(jdbc, n + 2, 3);
        report.WriteData("板材", n + 1, 4);
        string jdzb = BLLFactory.CreateJbBLL().JDZBL(bt, et);
        report.WriteData(jdzb, n + 2, 4);
        report.WriteData("CSP库存", n + 1, 5);
        string tgr = BLLFactory.CreateJbBLL().JDTGRL(bt, et);
        string tgl = BLLFactory.CreateJbBLL().JDTGLL(bt, et);
        decimal tgrkc = 0;
        if (tgr != "")
            tgrkc = Convert.ToDecimal(tgr);
        decimal tglkc = 0;
        if (tgl != "")
            tglkc = Convert.ToDecimal(tgl);
        decimal csp = tgrkc + tglkc;
        report.WriteData(csp.ToString("f2"), n + 2, 5);
        report.WriteData("CSP合格", n + 1, 6);
        string tgrh = BLLFactory.CreateJbBLL().JDTGRHL(bt, et);
        string tglh = BLLFactory.CreateJbBLL().JDTGLHL(bt, et);
        decimal tgrhg = 0;
        if (tgrh != "")
            tgrhg = Convert.ToDecimal(tgrh);
        decimal tglhg = 0;
        if (tglh != "")
            tglhg = Convert.ToDecimal(tglh);
        decimal csph = tgrhg + tglhg;
        report.WriteData(csph.ToString("f2"), n + 2, 6);
        report.WriteData("CSP可利用", n + 1, 7);
        string tgk = BLLFactory.CreateJbBLL().JDTGRKL(bt, et);
        report.WriteData(tgk, n + 2, 7);
        report.WriteData("CSP未缴库", n + 1, 8);
        string tgrw = BLLFactory.CreateJbBLL().JDTGRWL(bt, et);
        string tglw = BLLFactory.CreateJbBLL().JDTGLWL(bt, et);
        decimal tgrwj = 0;
        if (tgrw != "")
            tgrwj = Convert.ToDecimal(tgrw);
        decimal tglwj = 0;
        if (tglw != "")
            tglwj = Convert.ToDecimal(tglw);
        decimal cspw = tgrwj + tglwj;
        report.WriteData(cspw.ToString("f2"), n + 2, 8);
        report.WriteData("不锈钢库存", n + 1, 9);
        string bxr = BLLFactory.CreateJbBLL().JDBXRL(bt, et);
        string bxl = BLLFactory.CreateJbBLL().JDBXLL(bt, et);
        decimal bxrk = 0;
        if (bxr != "")
            bxrk = Convert.ToDecimal(bxr);
        decimal bxlk = 0;
        if (bxl != "")
            bxlk = Convert.ToDecimal(bxl);
        decimal bxk = bxrk + bxlk;
        report.WriteData(bxk.ToString("f2"), n + 2, 9);
        report.WriteData("不锈钢合格", n + 1, 10);
        string bxrh = BLLFactory.CreateJbBLL().JDBXRHL(bt, et);
        string bxlh = BLLFactory.CreateJbBLL().JDBXLHL(bt, et);
        decimal bxrhg = 0;
        if (bxrh != "")
            bxrhg = Convert.ToDecimal(bxrh);
        decimal bxlhg = 0;
        if (bxlh != "")
            bxlhg = Convert.ToDecimal(bxlh);
        decimal bxh = bxrhg + bxlhg;
        report.WriteData(bxh.ToString("f2"), n + 2, 10);
        report.WriteData("不锈钢可利用", n + 1, 11);
        string bxkc = BLLFactory.CreateJbBLL().JDBXRKL(bt, et);
        report.WriteData(bxkc, n + 2, 11);
        report.WriteData("板材库", n + 2, 12);
        report.WriteData("库存", n + 1, 13);
        report.WriteData("合格", n + 1, 14);
        report.WriteData("未缴库", n + 1, 15);
        DataSet ds11 = BLLFactory.CreateJbBLL().ZBKCL(bt, et);
        string zbkc = ds11.Tables[0].Rows[0]["zbkc"].ToString();
        report.WriteData(zbkc, n + 2, 13);
        string zbhg = ds11.Tables[0].Rows[0]["zbhg"].ToString();
        report.WriteData(zbhg, n + 2, 14);
        string zbwj = ds11.Tables[0].Rows[0]["zbwj"].ToString();
        report.WriteData(zbwj, n + 2, 15);
        report.WriteData("其它库库存", n + 4, 1);
        report.WriteData("一高线", n + 3, 2);
        string xc1g = BLLFactory.CreateJbBLL().XCKCL("一高线", bt, et);
        string bc1g = BLLFactory.CreateJbBLL().BCKCL("一高线", bt, et);
        decimal xc1gkc = 0;
        if (xc1g != "")
            xc1gkc = Convert.ToDecimal(xc1g);
        decimal bc1gkc = 0;
        if (bc1g != "")
            bc1gkc = Convert.ToDecimal(bc1g);
        decimal kc1g = xc1gkc + bc1gkc;
        report.WriteData(kc1g.ToString("f2"), n + 4, 2);
        report.WriteData("二高线", n + 3, 3);
        string xc2g = BLLFactory.CreateJbBLL().XCKCL("二高线", bt, et);
        decimal xc2gkc = 0;
        if (xc2g != "")
            xc2gkc = Convert.ToDecimal(xc2g);
        report.WriteData(xc2gkc.ToString("f2"), n + 4, 3);
        report.WriteData("大棒线", n + 3, 4);
        string bcbg = BLLFactory.CreateJbBLL().BCKCL("大棒线", bt, et);

        decimal bcbgkc = 0;
        if (bcbg != "")
            bcbgkc = Convert.ToDecimal(bcbg);
        report.WriteData(bcbgkc.ToString("f2"), n + 4, 4);
        report.WriteData("四轧库", n + 3, 5);
        string bc4g = BLLFactory.CreateJbBLL().BCKCL("四轧库", bt, et);

        decimal bc4gkc = 0;
        if (bc4g != "")
            bc4gkc = Convert.ToDecimal(bc4g);
        report.WriteData(bc4gkc.ToString("f2"), n + 4, 5);
        report.WriteData("酸洗库", n + 3, 6);
        string sxkc = BLLFactory.CreateJbBLL().SXKCL(bt, et);
        report.WriteData(sxkc, n + 4, 6);

        n = n + 5;
        report.CellsUnite(n, 1, n, 8);
        report.WriteData("交班设备情况", n, 1);
        report.CellsAlignment(n, 1, n, 8, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        DataSet ds12 = BLLFactory.CreateJbBLL().JBSBH(bt, et);
        report.WriteData("库区", n + 1, 1);
        report.WriteData("班别", n + 1, 2);
        report.CellsUnite(n, 3, n, 8);
        report.WriteData("设备情况", n, 3);
        report.CellsAlignment(n, 3, n, 8, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        int c = ds12.Tables[0].Rows.Count;
        if (c != 0)
        {
            for (int p = 0; p < c; p++)
            {
                int q = n + p + 2;
                report.CellsUnite(q, 3, q, 8);
                report.WriteData(ds12.Tables[0].Rows[p]["shebei"].ToString(), q, 3);
                report.CellsAlignment(q, 3, q, 8, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
            }
        }
        report.CellsUnite(n, 9, n, 16);
        report.WriteData("交班延续业务", n, 9);
        report.CellsAlignment(n, 9, n, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("库区", n + 1, 9);
        report.WriteData("班别", n + 1, 10);
        report.CellsUnite(n + 1, 11, n + 1, 16);
        report.WriteData("延续业务", n + 1, 11);
        report.CellsAlignment(n + 1, 11, n + 1, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        DataSet ds13 = BLLFactory.CreateJbBLL().JBYXH(bt, et);
        int g = ds13.Tables[0].Rows.Count;
        if (g != 0)
        {
            for (int h = 0; h < g; h++)
            {
                int a = n + h + 2;
                report.CellsUnite(a, 11, a, 16);
                report.WriteData(ds13.Tables[0].Rows[h]["yanxu"].ToString(), a, 11);
                report.CellsAlignment(a, 11, a, 16, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
            }
        }
        report.SaveAsHtml(Server.MapPath("1.html"));

    }
}
